package com.hnust.fiveonesix.Controller.LogiorRegiController;

import com.hnust.fiveonesix.Mapper.LogiorRegiMapper.LoginMapper;
import com.hnust.fiveonesix.Mapper.LogiorRegiMapper.RegisterMapper;
import com.hnust.fiveonesix.POJO.RegisterInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class RegisterController {
    @Autowired
    private RegisterMapper registerMapper;

    @Autowired
    private LoginMapper loginMapper;
    @RequestMapping("/register")
    public String Register(@RequestParam("账号") String userName,
                         @RequestParam("密码") String pwd,
                         @RequestParam("真实姓名") String name,
                         @RequestParam("电话") String tel,
                         @RequestParam("收货地址") String place,
                           @RequestParam("QQ") Integer QQ,
                           @RequestParam("邮箱") String mail,
                            @RequestParam("同意") Integer agree){
        String username ='%' + userName+'%';
        if(agree==0)
            return "forward:/登录注册失败/请先同意相关协议才能注册.html";

        RegisterInfo registerInfo = registerMapper.selectUserInfo(username);

        if (registerInfo==null){
            registerMapper.insertUserinfo(userName,pwd,name,tel,place,QQ,mail);
            loginMapper.inserUserinfo(userName,pwd);
            return "商城模板部分/商城首页";
        }
        else return "forward:/登录注册失败/账号已存在.html";
    }
}
